#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <qglobal.h>//基本数据类型
#include "smart_plc.h"

#include <QDebug>
#include <QMessageBox>
#include <QString>
#include "comfunc.h"
#include "mainwindow.h"

//广播报文示例                         |infor      |body
//广播C012继电器动作：          |seq|len|cmd|  gid  |did |ctrl|data| CS
//7E 01 00 00 00  FF FF FF FF  01  07  07  41 00  12 C0 01  82  xx


#define uint8 quint8

#define ID_LEN          0x04
#define CMD_LEN         1
#define DID_LEN         2


extern uint8 frame_buffer[];
//extern struct Cmd_Analy cmd_analy[];

struct SHS_frame
{
    uint8 stc;
    uint8 said[ID_LEN];
    uint8 taid[ID_LEN];
    uint8 seq;
    uint8 length;
    uint8 infor[1];
};

typedef struct
{
   char head;
   unsigned char type;
   unsigned char address[7];
   unsigned char cmd;
   unsigned char len;
   unsigned char did[2];
   unsigned char data[1];//[0]为SEQ，[1]为data
}proto_188_type;



//struct SHS_local_frame
//{
//    uint8 stc;

//    union
//    {
//        uint8 said[ID_LEN];
//        quint32 said_u32;
//    };
//    union
//    {
//        uint8 taid[ID_LEN];
//        quint32 taid_u32;
//    };
//    uint8 seq;
//    uint8 length;
//    uint8 did;
//    union
//    {
//        uint8 data[1];
//        quint16 data_u16;
//        quint32 data_u32;
//        quint64 data_u64;
//    };

//};
struct SHS_local_frame
{
    uint8 stc;


        uint8 said[ID_LEN];

        uint8 taid[ID_LEN];

    uint8 seq;
    uint8 length;
    uint8 did;

    uint8 data[2];


};
struct FBD_Frame
{
    uint8 cmd;
    uint8 did[2];
    uint8 ctrl;
    uint8 data[1];
};


struct FBD_body
{
    uint8 did[2];
    uint8 ctrl;
    uint8 data[1];
};

#define SHS_FRAME_HEAD 11
#define STC 0X7E

struct Cmd_Analy
{
    uint8 cmd;
    const char* analy_str;//cmd的解析内容
};

struct SHS_frame *get_smart_frame(uint8 rxframe_raw[],uint8 rxlen);
QString get_7E_remote_cmd_analysis(uint8 cmd);
void get_7E_did_analysis(QString did_str, QString &AnalyStr, QString &analysisType);
void get_7E_body_analysis(struct FBD_body *body, QString &AnalyStr);
void analysis_7E_frame(struct SHS_frame *pframe, QString &AnalyStr);
#endif // PROTOCOL_H
